﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace Irrlicht.Net.IO
{
    public class FileSystem : ReferenceCounted
    {
        #region PInvoke
        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool FileSystem_addFileArchive(IntPtr fs, 
            [MarshalAs(UnmanagedType.AnsiBStr)] string path, bool ignoreCase, bool ignorePaths, uint archiveType, string password);
        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool FileSystem_addFolderFileArchive(IntPtr fs, 
            [MarshalAs(UnmanagedType.AnsiBStr)] string filename, bool ignoreCase, bool ignorePaths);
        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool FileSystem_addPakFileArchive(IntPtr fs, 
            [MarshalAs(UnmanagedType.AnsiBStr)] string filename, bool ignoreCase, bool ignorePaths);
        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool FileSystem_addZipFileArchive(IntPtr fs, 
            [MarshalAs(UnmanagedType.AnsiBStr)] string filename, bool ignoreCase, bool ignorePaths);

        #endregion

        internal static FileSystem CreateFileSystem(IntPtr pointer)
        {
            FileSystem fileSystem = new FileSystem();
            fileSystem.pointer = pointer;
            return fileSystem;
        }

        public bool AddFileArchive(string path)
        {
            return AddFileArchive(path, true, true, ArchiveTypes.Unknown, "");
        }

        public bool AddFileArchive(string path, bool ignoreCase, bool ignorePaths, ArchiveTypes archiveType, string password)
        {
            return FileSystem_addFileArchive(pointer, path, ignoreCase, ignorePaths, (uint)archiveType, password);
        }

        public bool AddFolderFileArchive(string path)
        {
            return AddFolderFileArchive(path, true, true);
        }

        public bool AddFolderFileArchive(string path, bool ignoreCase, bool ignorePaths)
        {
            return FileSystem_addFolderFileArchive(pointer, path, ignoreCase, ignorePaths);
        }

        public bool AddPakFileArchive(string path)
        {
            return AddPakFileArchive(path, true, true);
        }

        public bool AddPakFileArchive(string path, bool ignoreCase, bool ignorePaths)
        {
            return FileSystem_addPakFileArchive(pointer, path, ignoreCase, ignorePaths);
        }

        public bool AddZipFileArchive(string path)
        {
            return AddZipFileArchive(path, true, true);
        }

        public bool AddZipFileArchive(string path, bool ignoreCase, bool ignorePaths)
        {
            return FileSystem_addZipFileArchive(pointer, path, ignoreCase, ignorePaths);
        }

    }
}
